/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package inet.controller;

import static inet.constant.Month.month;
import inet.dao.TimeKeepingDAO;
import inet.dao.UserDAO;
import inet.entity.TimeKeeping;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.bean.SessionScoped;

/**
 *
 * @author ÂuNgọcThái
 */
@ManagedBean
@SessionScoped
public class TimeKeepingController {

    /**
     * Creates a new instance of TimeKeepingController
     */
    List<String> dayOfMonth = null;
    TimeKeeping timekeep = null;
    List<TimeKeeping> lstTimeKeep = null;
    TimeKeepingDAO tkDAO = null;

    public TimeKeepingController() {
        dayOfMonth = new ArrayList<String>();
        timekeep = new TimeKeeping();
        lstTimeKeep = new ArrayList<TimeKeeping>();
        tkDAO= new TimeKeepingDAO();
    }

    public TimeKeepingDAO getTkDAO() {
        return tkDAO;
    }

    public void setTkDAO(TimeKeepingDAO tkDAO) {
        this.tkDAO = tkDAO;
    }

    public TimeKeeping getTimekeep() {
        return timekeep;
    }

    public void setTimekeep(TimeKeeping timekeep) {
        this.timekeep = timekeep;
    }

    public List<TimeKeeping> getLstTimeKeep() {
        return lstTimeKeep;
    }

    public void setLstTimeKeep(List<TimeKeeping> lstTimeKeep) {
        this.lstTimeKeep = lstTimeKeep;
    }

    public List<String> getDayOfMonth() {
        return dayOfMonth;
    }

    public void setDayOfMonth(List<String> dayOfMonth) {
        this.dayOfMonth = dayOfMonth;
    }

    public int countDateOfMonth(String m) {
        int day = 31;
        SimpleDateFormat sd = new SimpleDateFormat("MM/yyyy");
        try {
            Date d = sd.parse(m);
            Calendar c = Calendar.getInstance();
            c.setTime(d);
            day = c.getActualMaximum(Calendar.DAY_OF_MONTH);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return day;
    }

    public List<String> countMonth() {
        int i = 0;
        while (i < countDateOfMonth("3/2015")) {
            i++;
            month.add(month.get(i));
        }
        return month;
    }

    public List<TimeKeeping> getlstTimeKeep() {
        tkDAO= new TimeKeepingDAO();
        lstTimeKeep=tkDAO.getAll();
        return lstTimeKeep;
    }
}
